/**
 * Created by IAN on 2016/10/14.
 */
$(function () {
    var sel = $.Params.create();
    sel.addParams("page",0);
    sel.addParams("rows",rows);
    getData();

    //查询
    $("#searchBtn").on("click",function(){
        var searchVal = $("#searchVal").val();
        sel.addParams("liveTitle",searchVal);
        getData();
    })

    //判断checkbox状态
    $("#selAll").on("click",function () {
        if(!$(this).attr("checked")){
            $("input[type=checkbox]").attr("checked","checked")
        }else{
            $("input[type=checkbox]").removeAttr("checked");
        }
    })

    //添加事件
    $('#addDataBtn').on("click",function(){
        window.location.href="../MET_Manage/addLiveRoom.html";
    });

    //删除事件
    $('#delBtn').on("click",function(){
        var pararms = getCheckData();
        delData(pararms);
    });

    //获取数据
    function getData(){
        getPageData(sel,getIP()+"metLive/getMETlist",function(data){
            if(data.success){
                var html = "";
                var note = "";

                $.each(data.result, function(i,val) {
                    if(val.remark == "" || val.remark == null){
                        note = "";
                    }else{
                        note = val.remark;
                    }
                    html+="<tr role='row'' class='even'><td><input eid='"+val.id+"' onclick='getCheck(this)' type='checkbox' class='classOption'></td><td>"+parseInt(i+1)+"</td><td class='sorting_1'>"+val.liveTitle+
                          "</td><td>"+val.startTime+" "+val.endTime+"</td>"+
                          "<td>"+note+"</td><td><button type='button' class='btn btn-primary' uid='"+val.id+"' onclick='updateInfo(this)'>修改</button></td></tr>";
                });
                $("#listContainer").html(html);
            }
        })
    }

    //删除数据
    function delData(ids){
        if(!ids == "") {
            var del = $.Params.create();
            del.addParams("params", ids)
            del.ajax(getIP() + "metLive/deleteNews", function (data) {
                if (data.success) {
                    alert("删除成功！");
                    getData();
                }
            })
        }else{
            alert("请至少选择一项");
        }
    }

    //修改数据
    updateInfo = function (obj) {
        var dataId = $(obj).attr("uid");
        window.location.href=getIP()+"MET_Manage/updateLiveRoom.html?uid="+dataId;
    }
});
